package ${package.ServiceImpl};

import ${package.Entity}.${entity};
import ${package.Mapper}.${table.mapperName};
import ${package.Service}.${table.serviceName};
import ${superServiceImplClassPackage};
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
<#if pojoConfig.fo>
import ${pojoPackage}.fo.${entity}Fo;
import cn.hutool.core.lang.Assert;
import org.springframework.beans.BeanUtils;
</#if>
<#if pojoConfig.vo>
import ${pojoPackage}.vo.${entity}Vo;
</#if>
<#if pojoConfig.qo>
import ${pojoPackage}.qo.${entity}Qo;
import ${pojoPackage}.to.${entity}To;
import pers.yurwisher.rubick.common.wrapper.PageR;
</#if>

/**
 * <p>
 * ${table.comment!} 服务实现类
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Service
<#if kotlin>
open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} {

}
<#else>
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} {
    <#if pojoConfig.fo>

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void create(${entity}Fo fo) {
        ${entity} ${entity?uncap_first} = new ${entity}();
        BeanUtils.copyProperties(fo,${entity?uncap_first});
        baseMapper.insert(${entity?uncap_first});
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(${table.commonFields[0].propertyType} id,${entity}Fo fo) {
        ${entity} ${entity?uncap_first} = baseMapper.selectById(id);
        Assert.notNull(${entity?uncap_first});
        BeanUtils.copyProperties(fo,${entity?uncap_first});
        baseMapper.updateById(${entity?uncap_first});
    }
    </#if>
    <#if pojoConfig.vo>

    @Override
    public ${entity}Vo get(${table.commonFields[0].propertyType} id) {
       return baseMapper.get(id);
    }
    </#if>

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(${table.commonFields[0].propertyType} id){
        baseMapper.deleteById(id);
    }

    <#if pojoConfig.qo>
    @Override
    @SuppressWarnings("unchecked")
    public PageR<#noparse><</#noparse>${entity}To<#noparse>></#noparse> list(${entity}Qo qo) {
      return super.toPageR(baseMapper.list(super.toPage(qo), qo));
    }

    </#if>
}
</#if>
